home *** CD-ROM | disk | FTP | other *** search
/ Sun Solutions 1997 April to September / Sun Solutions CD - APR '97 - SEP '97 (704-3778-12 Rev. H)(Sun Microsystems, Inc.)(1997).iso / products / .wais / makedesc.bak < prev    next >
Text File  |  1995-08-22  |  14KB  |  628 lines

  1. #!/net/pinatubo/opt/PUBperl5/bin/perl5
  2. # /export/scratch/illustra/bin/perl5
  3. # /opt/PUBperl5/bin/perl5
  4. #
  5. # makedesc.pl
  6. #
  7. # Generate The Wais Tree
  8. #
  9. # Copyright Creative Dynamics, Inc. 1995
  10. #
  11. #$dirn = $0;
  12. #$dirn =~ s#(.*)/.*$#$1#;
  13. #require "$dirn/common.pl";
  14.  
  15. $CATDB_NAME = "catalyst";
  16. $USER = "miadmin";
  17.  
  18. #
  19. # use the libmi stuff
  20. #
  21.  
  22. use Mi;
  23.  
  24. $lastCategory = "";
  25. $lastSubCategory = "";
  26. $chapterCount = 0;
  27. $fileOpen = 0;
  28.  
  29. ### Set up output directory
  30.  
  31. $outputDirectory = "wais-src";
  32. umask(022);
  33. mkdir($outputDirectory, 0777);        # make an output directory for book    
  34. chdir "$outputDirectory" || die "Can't cd to $outputDirectory\n";
  35. unlink(<*.*>);                # delete all existing files in the output directory
  36.  
  37. {
  38.    local($query,$num_col, @record);
  39.    local($db, $row_desc, $result, $row, $col, $row_num, $error);
  40.  
  41. ### the query
  42.  
  43. $query = "
  44. select  p.Product_id, p.SolCompatible,    
  45.     p.ProdCatName, p.ProdSubCat, p.ProdName, v.VendorName,
  46.     p.ProdShortDesc, p.ProdLongDesc,
  47.     p.ProdHomePage, p.ProdImage, p.SrcAvail, p.ProdSrcLang,
  48.     p.ProdSpecHand,
  49.     v.VendorAddr1, v.VendorAddr2, v.VendorAddr3, v.VendorCity,
  50.     v.VendorPostCode,
  51.     v.VendorState, v.VendorZip, v.VendorCountry,
  52.     v.VendorPhone1code, v.VendorPhone1,
  53.     v.VendorPhone2code, v.VendorPhone2,
  54.     v.VendorFaxCode, v.VendorFax,
  55.     v.VendorEmailCode, v.VendorEmail,
  56.     v.VendorURL
  57. from   Vendor v using(lock=table),
  58.        Assoc_ProdVend a using(lock=table),
  59.        Products p using(lock=table)
  60. where  a.ProdId = p.Product_id
  61. and    a.VendId = v.Vendor_id
  62. and    p.Product_id < 10
  63. order by p.ProdCatName, p.ProdSubCat, p.ProdName
  64. ;";
  65.  
  66. # where  p.Product_id < 50 -- use to limit
  67. # alternate order: order by p.ProdCatName, p.ProdSubCat, p.ProdName, v.VendorName
  68.  
  69. ### query the database
  70.  
  71.    ($db = Mi::open("$CATDB_NAME", "$USER", "") ) || die "Can't open Illustra database\n";
  72.  
  73.    (Mi::exec($db, "$query", 0) == 0) || die "Can't exec Illustra query\n";
  74.  
  75.    print "  Query Sent\n";
  76.  
  77.    (($result = Mi::get_result($db)) == 1) || die "Got bad result from Illustra\n";
  78.  
  79.    print "  Got Results\n";
  80.  
  81.    ($row_desc = Mi::get_row_desc_without_row($db)) || die "Error on row description \n";
  82.  
  83.    $num_col = Mi::column_count($row_desc);
  84.  
  85.    print "  Results Have $num_col Columns\n";
  86.  
  87.    $row_num = 0;
  88.    while ($row = Mi::next_row($db, \$error))
  89.    {
  90.     $row_num++;
  91.     print "   Processing row $row_num...\n";
  92.     foreach $col (0..$num_col-1)
  93.     {
  94.           Mi::value($row, $col, $colval, $retlen);
  95.           $record[$col] = $colval;
  96.     }
  97.  
  98. ### Fix the data
  99.  
  100. # map double occurrences of ' to single '
  101.  
  102.     foreach $count (2..12)
  103.     {
  104.         $record[$count] =~ s/\'\'/\'/g;
  105.     }
  106.  
  107. ### Trim trailing spaces
  108.     foreach $count (2..30)
  109.     {
  110.         $record[$count] =~ s/ *$//g;
  111.     }
  112.  
  113. ### Now print out the data for this product        
  114.  
  115.     if ($lastCategory ne $record[2])
  116.     {
  117.         ++$chapterCount;        # increment chapter count
  118.         $outputChapterFile = "chap" . $chapterCount";
  119.         mkdir($outputChapterFile, 0777);
  120.         chdir "$outputChapterFile" || die "Can't cd to $outputChapterFile\n";
  121.         unlink(<*>);
  122.         $lastCategory = $record[2];
  123.     }
  124.     if ($lastSubCategory ne $record[3])
  125.     {
  126.         chdir "..";
  127.         mkdir($record[3], 077);
  128.         chdir "$record[3]" || die "Can't cd to $record[3]\n";
  129.         inlink(<*>);
  130.     }
  131.  
  132.     &print_productheader($record[2]);
  133.     &print_specialpara("H3", &build_productindex($record[5]), $record[5]);
  134.     &print_specialpara("H4", &build_vendorindex($record[4] . ":" . $record[5]), $record[4]);
  135.  
  136. # 6 p.ProdShortDesc,
  137. # 7 p.ProdLongDesc,
  138.     # choose the Long Description if it exists
  139.     $description = ($record[7] =~ /\S/) ? $record[7] : $record[6];
  140.     &print_multi("P", $description);
  141.  
  142. # 8 p.ProdHomePage,
  143.     if ($record[8] =~ /\S/)
  144.     {
  145.         &print_para("I", $record[8]);
  146.     }
  147.  
  148. # 9 p.ProdImage,
  149.  
  150.     ### NO PRODUCT IMAGE SUPPORT, YET
  151.     #&print_anchor(6);
  152.  
  153. ### TEMP NEED TO FIX THIS 
  154.     # &print_para("P", "Platforms supported: SPARC");
  155.  
  156. # 10 p.SrcAvail,
  157.     $answer = ($record[10] =~ /t/) ? "yes" : "no";
  158.     &print_para("P", "Source available: $answer");
  159.  
  160. # 11 p.ProdSrcLang,
  161.     &print_para("P", "Language: $record[11]");
  162.  
  163. # 12 p.ProdSpecHand,
  164. #
  165. # remove [ and ] brackets, also fix spaces and comma
  166. #
  167.     $record[12] =~ s/^\[//g;
  168.     $record[12] =~ s/ *]$//g;
  169.     $record[12] =~ s/^ *,//g;
  170.     $record[12] =~ s/ +,/, /g;
  171.  
  172.     if ($record[12] =~ /\S/)
  173.     {
  174.         &print_para("P", "Additional Requirements: $record[12]");
  175.     }
  176.  
  177. # 5 v.VendorName,
  178.     &print_para("I", $record[5]);
  179.  
  180. # 13 v.VendorAddr1,
  181. # 14 v.VendorAddr2,
  182. # 15 v.VendorAddr3,
  183.     foreach $count (13..15)
  184.     {
  185.          &print_para("I", $record[$count]) if ($record[$count] =~ /\S/);
  186.     }
  187. # 16 v.VendorCity,
  188. # 17 v.VendorPostCode,
  189. # 18 v.VendorState,
  190. # 19 v.VendorZip,
  191. # 20 v.VendorCountry,
  192.     # $record[16] =~ s/ $//g;
  193.     $address = $record[16] . ",";
  194.     foreach $count (18..20)
  195.     {
  196.         $address .= " " . $record[$count] if ($record[$count] =~ /\S/);
  197.     }
  198.     &print_para("I", $address);
  199.  
  200.     &print_para("I","Postal Code: $record[17]") if ($record[17] =~ /\S/);
  201.  
  202. # 21 v.VendorPhone1code,
  203. # 22 v.VendorPhone1,
  204. # 23 v.VendorPhone2code,
  205. # 24 v.VendorPhone2,
  206. # 25 v.VendorFaxCode,
  207. # 26 v.VendorFax,
  208. # 27 v.VendorEmailCode,
  209. # 28 v.VendorEmail,
  210.  
  211. $text = "";
  212. $text = $record[21] . " " if ($record[21] =~ /\S/);
  213. &print_para("I","Phone1: $text$record[22]") if ($record[22] =~ /\S/);
  214. $text = "";
  215. $text = $record[23] . " " if ($record[23] =~ /\S/);
  216. &print_para("I","Phone2: $text$record[24]") if ($record[24] =~ /\S/);
  217. $text = "";
  218. $text = $record[25] . " " if ($record[25] =~ /\S/);
  219. &print_para("I","Fax: $text$record[26]") if ($record[26] =~ /\S/);
  220. $text = "";
  221. $text = $record[27] . " " if ($record[27] =~ /\S/);
  222. &print_para("I","E-mail: $text$record[28]") if ($record[28] =~ /\S/);
  223.  
  224. # 29 v.VendorURL
  225.  
  226.     &print_para("I",$record[29]) if ($record[29] =~ /\S/);
  227.  
  228. # 30 v.VendorLOGO
  229.  
  230.     ### NO VENDOR IMAGE SUPPORT, YET
  231.     #&print_anchor(6);
  232.  
  233. # End of Product
  234.     &print_para("HR", "");
  235.  
  236.    }
  237.  
  238.    Mi::close($db);
  239.  
  240.    print "Processed $row_num records\n";
  241. }
  242.  
  243.  
  244. ### TEMP TEST OF GRAPHIC
  245.     #&print_anchor(6);
  246.  
  247. # final stuff...
  248. if ($fileOpen)
  249. {
  250.     &print_chapterfooter();
  251.     close CHAPTER;    
  252. }
  253.  
  254. # process book file
  255. &createbook();
  256.  
  257. print "Book Complete\n";
  258.  
  259.  
  260. #------------------------------------------------------------------
  261. # SUBROUTINES
  262. #------------------------------------------------------------------
  263.  
  264. #------------------------------------------------------------------
  265. # build_productindex 
  266. #
  267. # subroutine build_productindex builds MIF for FrameMaker product index markers
  268.  
  269. sub build_productindex {
  270.     return &build_indexmarker(2, @_[0]);
  271. }
  272.  
  273.  
  274. #------------------------------------------------------------------
  275. # build_vendorindex 
  276. #
  277. # subroutine build_vendorindex builds MIF for FrameMaker vendor index markers
  278.  
  279. sub build_vendorindex {
  280.     return &build_indexmarker(2, @_[0]);
  281. }
  282.  
  283.  
  284. #------------------------------------------------------------------
  285. # build_indexmarker 
  286. #
  287. # subroutine build_indexmarker builds MIF for FrameMaker index markers
  288.  
  289. sub build_indexmarker {
  290.  
  291.     local($markerType, $indexEntry) = @_;
  292.  
  293.     return "<Marker <MType $markerType> <MText \`$indexEntry\'>>";
  294. }
  295.  
  296.  
  297. #------------------------------------------------------------------
  298. # print_specialpara 
  299. #
  300. # subroutine print_specialpara prints MIF for FrameMaker paragraph with a special character ie bullet
  301.  
  302. sub print_specialpara {
  303.  
  304.     local($tag) = @_[0];
  305.     local($specialchar) = @_[1]; 
  306.     local($string) = @_[2]; 
  307.  
  308.     print CHAPTER " <Para 
  309.   <PgfTag \`$tag\'>
  310.    <ParaLine $specialchar
  311.     <String \`$string\'>
  312.    >
  313.  > # end of Para\n";
  314. }
  315.  
  316.  
  317. #------------------------------------------------------------------
  318. # print_para 
  319. #
  320. # subroutine print_para prints MIF for FrameMaker paragraph
  321.  
  322. sub print_para {
  323.  
  324.     local($tag) = @_[0];
  325.     local($string) = @_[1]; 
  326.  
  327.     print CHAPTER " <Para 
  328.   <PgfTag \`$tag\'>
  329.    <ParaLine
  330.     <String \`$string\'>
  331.    >
  332.  > # end of Para\n";
  333. }
  334.  
  335. #------------------------------------------------------------------
  336. # print_uniquepara 
  337. #
  338. # subroutine print_para prints MIF for FrameMaker paragraph
  339.  
  340. sub print_uniquepara {
  341.  
  342.     local($device) = @_[0];
  343.     local($tag) = @_[1];
  344.     local($unique) = @_[2]; 
  345.     local($specialchar) = @_[3]; 
  346.     local($string) = @_[4]; 
  347.  
  348.     print $device " <Para 
  349.   <Unique $unique>
  350.   <PgfTag \`$tag\'>
  351.    <ParaLine $specialchar
  352.     <String \`$string\'>
  353.    >
  354.  > # end of Para\n";
  355. }
  356.  
  357.  
  358.  
  359. #------------------------------------------------------------------
  360. # print_multi 
  361. #
  362. # subroutine print_multi prints MIF for multiple FrameMaker paragraph
  363.  
  364. sub print_multi {
  365.  
  366.     local($tag) = @_[0];
  367.     local(@strings) = split(/\n/, @_[1]); 
  368.  
  369.     foreach $string (@strings)
  370.     {
  371.         if ($string =~ s/^--//)
  372.         {
  373.             &print_specialpara($tag, "<Char Bullet>", $string);
  374.         }
  375.         else
  376.         {
  377.             &print_para($tag, $string);
  378.         }
  379.     }
  380. }
  381.  
  382. #------------------------------------------------------------------
  383. # print_anchor 
  384. #
  385. # subroutine print_anchor prints MIF for FrameMaker anchored frame
  386.  
  387. sub print_anchor {
  388.  
  389.     local($id) = @_[0];
  390.  
  391.     print CHAPTER " <Para 
  392.   <ParaLine 
  393.    <AFrame $id>
  394.   >
  395.  > # end of Para\n";
  396. }
  397.  
  398. #------------------------------------------------------------------
  399. # print_productheader 
  400. #
  401. # subroutine print_chapterheader prints header for every chapter file
  402.  
  403. sub print_productheader {
  404.  
  405.     local($category) = @_[0];
  406.     local($string) = @_[1]; 
  407.  
  408.     print PRODUCT <<PRODUCTHEADER;
  409. <html>
  410. <head>
  411. <title>Solaris - "$category"</title>
  412. </head>
  413. <body>
  414. <A HREF="http://localhost:7999"><IMG SRC="../../../images/goto_toc.gif"> Catalyst Catalog Search Page</A> <A HREF="$string"><IMG SRC="../../../images/goto_back.gif"> Sub-category
  415. <HR>
  416. </A>
  417. PRODUCTHEADER
  418. }
  419.  
  420. #------------------------------------------------------------------
  421. # print_chapterfooter
  422. #
  423. # subroutine print_chapterfooter prints footer for every chapter file
  424.  
  425. sub print_chapterfooter {
  426.  
  427.    print CHAPTER <<CHAPTERFOOTER;
  428. > # end of TextFlow
  429. # End of Generated MIF File for the Sun Solutions Catalog
  430. CHAPTERFOOTER
  431.  
  432. }
  433.  
  434. #------------------------------------------------------------------
  435. # print_section
  436. #
  437. # subroutine print_section prints the section file for every chapter
  438.  
  439. sub print_section {
  440.  
  441.     local($category) = @_;
  442.     local($outputSectionFile, $cnt, $word, @words);
  443.  
  444.     $outputSectionFile = "sect" . $chapterCount . ".mif";
  445.     open(SECTION, ">$outputSectionFile") || do
  446.     {
  447.         die "Can't open SECTION file $outputSectionFile\n";
  448.     };
  449.  
  450.     #----------------------
  451.     # HEADER
  452.     print SECTION <<SECTIONHEADER;
  453. <MIFFile 4.00> # Developed by the Carl Group, Inc
  454. # for the Sun Solutions Catalog
  455. include(../secthead.mif)
  456.  
  457. SECTIONHEADER
  458.  
  459.  
  460.     @words = split(" ", $category);    # place into array
  461.     @words = grep(!/^ $/, @words);    # remove spaces
  462.     $cnt = @words;            # count elements
  463.     if ($cnt == 1)
  464.     {
  465.         &print_uniquepara(SECTION, "Chap Title", 123, "", "");
  466.         &print_uniquepara(SECTION, "Chap Title", 124, "", "");
  467.         &print_uniquepara(SECTION, "Chap Title", 125, "<AFrame 1>", @words[0]);
  468.     }
  469.     elsif ($cnt == 2)
  470.     {
  471.         &print_uniquepara(SECTION, "Chap Title", 123, "", "");
  472.         &print_uniquepara(SECTION, "Chap Title", 124, "", @words[0]);
  473.         &print_uniquepara(SECTION, "Chap Title", 125, "<AFrame 1>", @words[1]);
  474.     }
  475.     elsif ($cnt == 3)
  476.     {
  477.         &print_uniquepara(SECTION, "Chap Title", 123, "", @words[0]);
  478.         &print_uniquepara(SECTION, "Chap Title", 124, "", @words[1]);
  479.         &print_uniquepara(SECTION, "Chap Title", 125, "<AFrame 1>", @words[2]);
  480.     }
  481.  
  482.     print SECTION <<SECTIONBODY;
  483. > # end of TextFlow
  484. <TextFlow 
  485.  <Para 
  486.   <Unique 95>
  487.   <PgfTag `Chap Head'>
  488.   <ParaLine 
  489.    <TextRectID 12>
  490.   >
  491.  > # end of Para
  492.  <Para 
  493.   <Unique 100>
  494.   <PgfTag `Chap Head'>
  495.   <ParaLine 
  496. SECTIONBODY
  497.     print SECTION "   <String `SECTION $chapterCount'>  # Section with Number\n  >\n > # end of Para\n";
  498.  
  499.     #-------------------------
  500.     # FOOTER
  501.     print SECTION <<SECTIONFOOTER;
  502. > # end of TextFlow
  503. # End of MIFFile
  504. SECTIONFOOTER
  505.  
  506.     close SECTION;
  507. }
  508.  
  509. #------------------------------------------------------------------
  510. # createbook
  511. #
  512. # subroutine createbook creates the MIF version of a book
  513.  
  514. sub createbook {
  515.  
  516.         local($bookFile, $chapter);
  517.  
  518.     $bookFile = "ssc.mif";
  519.     open(BOOK, ">$bookFile") || do
  520.     {
  521.         die "Can't open CHAPTER file $bookFile\n";
  522.     };
  523.  
  524.     &print_bookheader();
  525.     for(1..$chapterCount)
  526.     {
  527.         &print_bookcomponent($_);
  528.     }
  529.     &print_bookfooter();
  530.  
  531. }
  532.  
  533.  
  534. #------------------------------------------------------------------
  535. # print_bookheader
  536. #
  537. # subroutine print_bookheader prints MIF header for the book file
  538.  
  539. sub print_bookheader {
  540.  
  541.     print BOOK <<BOOKHEADER
  542. <Book 4.0> # Generated by The Carl Group, Inc
  543. # for the Sun Solutions Catalog
  544. <BookComponent 
  545.  <FileName `<c\\>sscTOC.doc'>
  546.  <FileNameSuffix `TOC'>
  547.  <DeriveLinks No >
  548.  <DeriveType TOC >
  549.  <DeriveTag `H1'>
  550.  <DeriveTag `H2'>
  551.  <StartPageSide ReadFromFile >
  552.  <PageNumbering Continue >
  553.  <PgfNumbering Continue >
  554.  <PageNumPrefix `'>
  555.  <PageNumSuffix `'>
  556.  <DefaultPrint Yes >
  557.  <DefaultApply Yes >
  558.  <DefaultDerive Yes >
  559. > # end of BookComponent
  560. BOOKHEADER
  561.  
  562. }
  563.  
  564. #------------------------------------------------------------------
  565. # print_bookcomponent
  566. #
  567. # subroutine print_bookcomponent prints MIF header for every component in the book file
  568.  
  569. sub print_bookcomponent {
  570.  
  571.         local($component, $section, $chapter) = @_[0];
  572.  
  573.     $section = "sect" . $component . ".doc";
  574.     $chapter = "chap" . $component . ".doc";
  575.  
  576.     print BOOK <<BOOKCOMPONENT
  577. <BookComponent 
  578.  <FileName `<c\\>$section'>
  579.  <StartPageSide ReadFromFile >
  580.  <PageNumbering Continue >
  581.  <PgfNumbering Continue >
  582.  <PageNumPrefix `'>
  583.  <PageNumSuffix `'>
  584.  <DefaultPrint Yes >
  585.  <DefaultApply Yes >
  586. > # end of BookComponent
  587. <BookComponent 
  588.  <FileName `<c\\>$chapter'>
  589.  <StartPageSide ReadFromFile >
  590.  <PageNumbering Continue >
  591.  <PgfNumbering Continue >
  592.  <PageNumPrefix `'>
  593.  <PageNumSuffix `'>
  594.  <DefaultPrint Yes >
  595.  <DefaultApply Yes >
  596. > # end of BookComponent
  597. BOOKCOMPONENT
  598.  
  599. }
  600.  
  601. #------------------------------------------------------------------
  602. # print_bookfooter
  603. #
  604. # subroutine print_bookfooter prints MIF footer for the book file
  605.  
  606. sub print_bookfooter {
  607.  
  608.    print BOOK <<BOOKFOOTER;
  609. <BookComponent 
  610.  <FileName `<c\\>sscIX.doc'>
  611.  <FileNameSuffix `IX'>
  612.  <DeriveLinks No >
  613.  <DeriveType IDX >
  614.  <DeriveTag `Index'>
  615.  <StartPageSide ReadFromFile >
  616.  <PageNumbering Continue >
  617.  <PgfNumbering Continue >
  618.  <PageNumPrefix `'>
  619.  <PageNumSuffix `'>
  620.  <DefaultPrint Yes >
  621.  <DefaultApply Yes >
  622.  <DefaultDerive Yes >
  623. > # end of BookComponent
  624. # end of Book
  625. BOOKFOOTER
  626.  
  627. }
  628.